package com.qckj.amz.controller;

import com.qckj.amz.domain.ProductFmlAttr;
import com.qckj.amz.service.IProductFmlAttrService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 产品附加属性Controller
 *
 * @author luchuan
 * @since 1.0 2022-03-03
 */
@RestController
@RequestMapping("/amz/productFmlAttr")
public class ProductFmlAttrController extends BaseController {
    @Autowired
    private IProductFmlAttrService productFmlAttrService;

    /**
     * 查询产品附加属性列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductFmlAttr productFmlAttr) {
        Page<ProductFmlAttr> page = productFmlAttrService.findProductFmlAttrPage(productFmlAttr);
        return getDataTable(page);
    }

    /**
     * 导出产品附加属性列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:export')")
    @Log(title = "产品附加属性", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductFmlAttr productFmlAttr) {
        List<ProductFmlAttr> list = productFmlAttrService.findProductFmlAttrList(productFmlAttr);
        ExcelUtil<ProductFmlAttr> util = new ExcelUtil<>(ProductFmlAttr.class);
        return util.exportExcel(list, "productFmlAttr");
    }

    /**
     * 获取产品附加属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:query')")
    @GetMapping(value = "/{productCode}")
    public AjaxResult getInfo(@PathVariable("productCode") String productCode) {
        return AjaxResult.success(productFmlAttrService.findById(productCode));
    }

    /**
     * 新增产品附加属性
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:add')")
    @Log(title = "产品附加属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductFmlAttr productFmlAttr) {
        productFmlAttrService.save(productFmlAttr);
        return AjaxResult.success();
    }

    /**
     * 修改产品附加属性
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:edit')")
    @Log(title = "产品附加属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductFmlAttr productFmlAttr) {
        productFmlAttrService.save(productFmlAttr);
        return AjaxResult.success();
    }

    /**
     * 删除产品附加属性
     */
    @PreAuthorize("@ss.hasPermi('amz:productFmlAttr:remove')")
    @Log(title = "产品附加属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productCodes}")
    public AjaxResult remove(@PathVariable String[] productCodes) {
        productFmlAttrService.deleteByIds(Arrays.asList(productCodes));
        return AjaxResult.success();
    }
}
